package com.gvsoft.analyse.packet;

import com.gvsoft.Config;
import com.gvsoft.analyse.inf.IPacket;
import org.apache.commons.lang3.StringUtils;

/**
 * Created with IntelliJ IDEA.
 * ProjectName:gvMsgRouting
 * Author: zhaoqiubo
 * Date: 15/8/7
 * Time: 下午3:19
 * Desc: 从客户端接收的报文抽象类
 */
public  class Packet implements IPacket{

    String header;
    String rid;
    String clientToken;
    String packetBody;

    public String getHeader() {
        return header;
    }

    public void setHeader(String header) {
        this.header = header;
    }

    public String getRid() {
        return rid;
    }

    public void setRid(String rid) {
        this.rid = rid;
    }

    public String getClientToken() {
        return clientToken;
    }

    public void setClientToken(String clientToken) {
        this.clientToken = clientToken;
    }

    public String getPacketBody() {
        return packetBody;
    }

    public void setPacketBody(String packetBody) {
        this.packetBody = packetBody;
    }

    public void generatePacket(String header, String rid, String clientToken, String packetBody) {
        this.header = header;
        this.packetBody = packetBody;
        this.rid = rid;
        this.clientToken = clientToken;
    }

    public void generatePacket(String header, String rid, String clientToken) {
        this.header = header;
        this.rid = rid;
        this.clientToken = clientToken;
    }

    /**
     * 返回当前
     * @return
     */
    public String getPacketStr() {

        StringBuffer sb = new StringBuffer();
        sb.append(this.getHeader());
        if(!StringUtils.isBlank(this.getRid())){
            sb.append("|").append(this.getRid());
        }
        if(!StringUtils.isBlank(this.getClientToken())){
            sb.append("|").append(this.getClientToken());
        }
        if(!StringUtils.isBlank(this.getPacketBody())){
            sb.append("|").append(this.getPacketBody());
        }
        return sb.toString();

    }
}
